/**
 * 
 */
package com.zhanggz.mypattern.factory;

/**
 * 发型工厂类
 * 
 * @author alex
 * @Date Jun 22, 2015
 */
public class HairFactory {

	/**
	 * 根据key值取具体实现类
	 * 
	 * @param key
	 * @return
	 */
	public HairInterface getHair(String key) {
		if ("Left".equals(key)) {
			return new LeftHair();
		} else if ("Right".equals(key)) {
			return new RightHair();
		}
		return null;
	}

	public HairInterface getHairByClass(String className) {
		try {
			HairInterface hair = (HairInterface) Class.forName(className)
					.newInstance();
			return hair;
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}
}